/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dis.service;

import java.util.Hashtable;
import java.util.Random;
import java.util.Vector;

/**
 *
 * @author manuelpamplona
 */
public class ServiceColors {
    
    public Hashtable<String,String> valores;
    public static Vector<String> colors = new Vector<String>();
    
    public ServiceColors(){
        valores = new Hashtable<String,String>();
        valores.put("1", "1");
        valores.put("2", "2");
        valores.put("3", "3");
        valores.put("4", "4");
        valores.put("5", "5");
        valores.put("6", "6");
        valores.put("7", "7");
        valores.put("8", "8");
        valores.put("9", "9");
        valores.put("10", "A");
        valores.put("11", "B");
        valores.put("12", "C");
        valores.put("13", "D");
        valores.put("14", "E");
        valores.put("15", "F");
    }
    
    public String getColorRandom(){
        String colorCode = "#";
        boolean isRepeat = true;
        while(isRepeat){
           for(int i = 0; i < 6; i++){
                colorCode += valores.get(getNumberRandom() + "");
            } 
           if(!hasColor(colorCode)){
               isRepeat = false;
               colors.add(colorCode);
           }
           else colorCode = "";
        }
        return colorCode;
    }
    
    
    private int getNumberRandom(){
        Random random = new Random();
        return random.nextInt(15) + 1;
    }
    
    private boolean hasColor(String color){
        boolean hasColor = false;
        for(int i = 0; i < colors.size(); i++){
            if(colors.get(i).compareToIgnoreCase(color) == 0) return true;
        }
        return hasColor;
    }
}
